<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>宇成建筑</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="../statics/css/font.css">
    <link rel="stylesheet" href="../statics/plugins/layui/css/layui.css">
    <link rel="stylesheet" href="../statics/css/xadmin.css">
    <link rel="stylesheet" href="../statics/css/style.css">
    <style>
        .layui-table td, .layui-table th {
            min-width: 60px;
        }
    </style>
</head>

<body class='labelAuto'>
<div class="x-nav">
        <span class="layui-breadcrumb">
            <a href="welcome.html">首页</a>
            <a href="javascript:;">仓库管理</a>
            <a href="javascript:;">仓库物资</a>
            <a>
                <cite>物资出入库记录</cite>
            </a>
        </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
    </a>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right;margin-right:10px"
       onclick="window.history.go(-1)" title="后退">
        <i class="iconfontBlod" style="line-height:30px">&#xe74f;</i>
    </a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body search">
                    <form action="" class="layui-form">
                        <div class="layui-form-item">
                            <div class="layui-inline" style="">
                                <label class="layui-form-label">日期</label>
                                <div class="layui-input-block">
                                    <input type="text" class="layui-input" id="startTime" placeholder="">
                                </div>
                                <div class="layui-input-block" style="width:10px;text-align: center">
                                    -
                                </div>
                                <div class="layui-input-block">
                                    <input type="text" class="layui-input" id="endTime" placeholder="">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">出入库类型</label>
                                <div class="layui-input-block" style="width:120px">
                                    <select name="logType" lay-verify="required" id="type">
                                        <option value="">-</option>
                                        <option value="1">采购</option>
                                        <option value="2">调拨入库</option>
                                        <option value="3">消耗</option>
                                        <option value="4">个人领料</option>
                                        <option value="7">班组领料</option>
                                        <option value="5">调拨出库</option>
                                        <option value="6">报损</option>
                                        <option value="8">退货</option>
                                    </select>
                                </div>
                            </div>
                            <!--                                <div class="layui-inline">-->
                            <!--                                    <label class="layui-form-label">物资类型</label>-->
                            <!--                                    <div class="layui-input-block">-->
                            <!--                                        <select name="city" lay-verify="required" id="buyType">-->
                            <!--                                            <option value="">-</option>-->
                            <!--                                            <option value="1">现金</option>-->
                            <!--                                            <option value="2">供应商</option>-->
                            <!--                                        </select>-->
                            <!--                                    </div>-->
                            <!--                                </div>-->
                            <div class="layui-inline">
                                <label class="layui-form-label">搜索</label>
                                <div class="layui-input-block">
                                    <input type="search" autocomplete="off" class="layui-input" id="searchInput">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <button class="layui-btn search" type="button" id='search'>
                                    <i class="iconfont layui-icon">&#xe615;</i>
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="layui-card-body tableCardBody">
                    <table class="layui-table" id="lists" lay-filter="test"></table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script src="../statics/plugins/layui/layui.js" charset="utf-8"></script>
<script src='../statics/plugins/jQuery-3.2.1/jquery-3.2.1.min.js'></script>
<script type="text/javascript" src="../statics/plugins/X-admin/xadmin.js"></script>
<script type="text/javascript" src="../statics/js/public.js?v=1129"></script>
<script type="text/javascript">
    layui.use(['form', 'layer', "table", "laydate"], function () {
        var table = layui.table;
        var laydate = layui.laydate;
        var form = layui.form;
        var materialId = getQueryString('materialId');
        var specId = getQueryString('specId');
        var projectId = getQueryString('projectId');
        form.render()
        var date = new Date();
        var curYear = date.getFullYear();
        var curMonth = date.getMonth() < 9 ? '0' + (date.getMonth() + 1) : (date.getMonth() + 1);
        var curDays = date.getDate() < 10 ? '0' + date.getDate(): date.getDate();
        date.setDate(date.getDate() - 30);
        var lastYear = date.getFullYear();
        var lastMonth = date.getMonth() < 9 ? '0' + (date.getMonth() + 1) : (date.getMonth() + 1);
        var lastDays = date.getDate() < 10 ? '0' + date.getDate(): date.getDate();
        materialId = materialId == null ? '' : materialId;
        if (materialId != '') {
            $('#searchInput').parent().parent().hide();
            $('#materialType').parent().parent().hide();
        }
        laydate.render({
            elem: '#startTime'
            , type: 'date'
            , value: lastYear + '-' + lastMonth + '-' + lastDays
            , max: 0
        });
        laydate.render({
            elem: '#endTime'
            , type: 'date'
            , value: curYear + '-' + curMonth + '-' + curDays
            , max: 0
        });
        // 异步数据加载
        var lists = table.render({
            elem: '#lists', //绑定DOM元素
            id: 'lists', //table的id
            title: '人员列表',
            height: 'full-150',
            contentType: "application/json; charset=utf-8",
            url: url + '/warehouse/warehouse/materialLog', //数据接口地址
            request: {
                pageName: 'page', //页码的参数名称，默认：page
                limitName: 'length' //每页数据量的参数名，默认：limit
            },
            method: 'POST',
            parseData: function (res) {
                return {
                    "code": res.code, //解析接口状态
                    "data": res.data.data,
                    "msg": res.msg,
                    "count": res.data.count,
                };
            },
            where: {
                projectId: projectId,
                materialId: materialId,
                specId: specId,
                startTime: lastYear + '-' + lastMonth + '-' + lastDays,
                endTime: curYear + '-' + curMonth + '-' + curDays,
                type: '',
                search: '',
                token: getToken()
            },
            toolbar: '#toolbar',
            defaultToolbar: ['filter'],
            page: false, //开启分页
            limit: 10, //默认每页记录条数
            limits: [10, 20, 50], //每页记录条数可选数量
            totalRow:true,
            cols: [
                [ //表头
                    {field: '', title: '编号', type: 'numbers', width: '60',totalRowText:'合计'},
                    {field: 'projectName', title: '项目名称', width: '180'},
                    {field: 'materialName', title: '材料名称', width: '180'},
                    {field: 'spec', title: '规格型号', width: '120'},
                    {
                        field: 'time', title: '出入库时间', width: '120', templet: function (d) {
                            return d.time.substr(0, 10);
                        }
                    },
                    // {field: 'surplus', title: '结余', width: '70'},
                    {field: 'amount', title: '出入库数量', width: '100',totalRow:true},
                    {field: 'unitName', title: '单位'},
                    {field: 'price', title: '收储价格（元）', width: '90'},
                    {field: 'totalPrice', title: '总价（元）', width: '100',totalRow:true},
                    {
                        field: 'type', title: '类型', width: '90', templet: function (d) {
                            switch (d.type) {
                                case 0:
                                    return '导入';
                                case 1:
                                    return '采购';
                                case 2:
                                    return '调拨入库';
                                case 3:
                                    return '消耗';
                                case 4:
                                    return '个人领料';
                                case 5:
                                    return '调拨出库';
                                case 6:
                                    return '报损';
                                case 7:
                                    return '班组领料';
                                default:
                                    return '-';
                            }
                        }
                    },
                    {
                        field: 'isCheck', title: '入库确认', width: '90', templet: function (d) {
                            if (d.type == 1) {
                                return d.isCheck === 0 ? '未确认' : '已确认';
                            } else {
                                return '-';
                            }
                        }
                    },
                    {
                        field: '', title: '来源', width: '90', templet: function (d) {
                            if (d.type === 2){
                                return d.sourceProjectName;
                            }else{
                                return '';
                            }
                        }
                    },
                    {
                        field: 'createTime', title: '记录时间', width: '100', templet: function (d) {
                            return (d.createTime).substr(0, 10);
                        }
                    },
                    {
                        field: 'status', title: '审核类型', width: '120', templet: function (d) {
                            if (d.status === 1) {
                                return '待提交';
                            } else if (d.status === 2) {
                                return '待审核';
                            } else if (d.status === 3) {
                                return '已通过';
                            } else if (d.status === 4) {
                                return '被驳回';
                            } else {
                                return '-';
                            }
                        }
                    },
                ]
            ],
            response: {
                statusName: 'code', //数据状态的字段名称，默认：code
                statusCode: 100000, //成功的状态码，默认：0
                msgName: 'msg', //状态信息的字段名称，默认：msg
                countName: 'count', //数据总数的字段名称，默认：count
                dataName: 'data' //数据列表的字段名称，默认：data
            },
            done: function () {
                permission();
            }
        });

        $('body').on('click', '#search', function () {
            var search = $('#searchInput').val();
            var startTime = $('#startTime').val();
            var endTime = $('#endTime').val();
            var type = $('#type').val();
            table.reload('lists', {
                where: {
                    projectId: projectId,
                    materialId: materialId,
                    startTime: startTime,
                    endTime: endTime,
                    type: type,
                    search: search,
                    token: getToken()
                }
            })
        })

    });
</script>
</html>